// CSE 142 Winter 2008, Marty Stepp // // A Cougar is a slow, dumb animal that lives in the Critters simulation. // A cougar moves 3 steps west, 3 steps east, and repeats. import java.awt.*; // for Color public class Cougar extends Critter { private int moves; public Cougar() { moves = 0; } public Color getColor() { return Color.RED; } // This method returns a single move for the Cougar to make on the screen. // To implement the overall 3-left, 3-right pattern, I need to count how many // moves I have made and use that information to know which way to move each time. public Direction getMove() { moves++; if (moves > 6) { moves = 1; } System.out.println("This is move #" + moves); if (moves <= 3) { return Direction.WEST; } else { return Direction.EAST; } // You can't use a for loop like this: // for (int i = 1; i <= 3; i++) { // return Direction.WEST; // } // for (int i = 1; i <= 3; i++) { // return Direction.EAST; // } } public String toString() { return "C"; } }